﻿<%@ WebService Language="C#" Class="Filial" %>

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Web;
using System.Web.Services;
using System.IO;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class Filial : System.Web.Services.WebService
{
    public Filial()
    {
    }

    [WebMethod]
    public bool gerarRelatorioRankingDiario()
    {
        var ranking = new SOA.DAL.Venda().GetRankingVendaDiaria(DateTime.Now);
        var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"Ranking"+DateTime.Now.ToString("ddMMyyyyHHmmss")+".txt");
        using(FileStream fs = File.Create(path)){
            using(StreamWriter sw = new StreamWriter(fs)){
                sw.WriteLine("ID_FILIAL;NOME;META;VENDA;RELACAO");
                foreach(var r in ranking){
                    sw.WriteLine(r.IdFilial + ";" + r.Nome + ";" + r.Meta.ToString("N2") + ";" + r.TotalVenda.ToString("N2") + ";" + r.Relacao.ToString("N2"));
                }
            }        
        }
        return true;
    }   
    
    [WebMethod]
    public SOA.MODEL.MetaFilial getMetaByFilial(int idFilial)
    {
        return new SOA.DAL.Filial().GetMetaByFilial(idFilial);
    }
    
    [WebMethod]
    public System.Collections.Generic.List<SOA.MODEL.MetaFilial> getMetas()
    {
        return new SOA.DAL.Filial().GetMetas();
    }

    [WebMethod]
    public SOA.MODEL.Filial getById(int idFilial)
    {
        return new SOA.DAL.Filial().GetById(idFilial);
    }

    [WebMethod]
    public System.Collections.Generic.List<SOA.MODEL.Filial> getFiliais()
    {
       return new SOA.DAL.Filial().GetFiliais();
    }

    [WebMethod]
    public bool adicionarPontoNegativo(int idFilial)
    {
        return new SOA.DAL.Filial().AdicionarPontoNegativo(idFilial);
    }
}
